package com.example.demo.controller;

import com.example.demo.entity.*;
import com.example.demo.mapper.BorrowMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.BorrowBookService;
import com.example.demo.utils.ResponseWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class UserController {
    @Autowired
    BorrowBookService borrowBookService;
    @Autowired
    BorrowMapper borrowMapper;
    @Autowired
    UserMapper userMapper;
    @RequestMapping("/myHistory")
    public ResponseWrapper myHistory(String username,int start){
        start=start*10;
        System.out.println("username++++"+username);
        int id = userMapper.getUserIdByUsername(username);
        List<UserHistory> userHistories = borrowMapper.myHistory(id);
        PageHelper.offsetPage(start,10);
        PageInfo pageInfo = new PageInfo(userHistories,10);
        System.out.println("id++++"+id);
        return ResponseWrapper.markSuccess(pageInfo);
    }
    @RequestMapping("/backBook")
    public ResponseWrapper backBook(int borrowId){
        System.out.println("id++++"+borrowId);

        return ResponseWrapper.markSuccess(borrowBookService.backBook(borrowId));
    }


}
